#!/bin/bash 
if [ -f "/opt/java8/jdk1.8.0_202/bin/java" ];then
    # 输入要执行的jar文件名  
    echo -n "执行文件:"   
    read jar_file 
    
    # 执行代码  
    /opt/java8/jdk1.8.0_202/bin/java -jar $jar_file -nogui
else
    # 没有文件下载
    echo -e "\e[93m 准备下载"
    # 下载 华为云的Java8
      wget https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
     
   # 判断文件夹是否存在
    if [ -d "/opt/java8/" ];then
       # 开始解压
       echo "\e[39m 准备解压"
       tar -zxvf jdk-8u202-linux-x64.tar.gz -C /opt/java8/
    else
       # 创建目录
       mkdir /opt/java8
       # 开始解压
       tar -zxvf jdk-8u202-linux-x64.tar.gz -C /opt/java8/
    fi
    
    # 判断文件是否解压成功   
    if [ -f "/opt/java8/jdk1.8.0_202/bin/java" ];then
       # 输入要执行的jar文件名     
       echo -n "执行文件:"   
       read jar_file  
       # 执行代码  
       /opt/java8/jdk1.8.0_202/bin/java -jar $jar_file -nogui
    else
       echo -e " \e[31m 安装失败 "
    fi

fi
